using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.UserContrl
{
	public class SnsUserPageItem : UserControl, MMItemCtrl
	{
		private enum AlbumItemStyle
		{
			albumCoverItem,
			albumImgItem,
			albumLoadingItem,
			unknown
		}
		public delegate void AlbumImageClick(object sender, object object_0);
		private const string TAG = "SnsUserPageItem";
		private AlbumCoverCtrl albumCoverCtrl;
		private Grid dataPanel;
		private AlbumDataControl albumDataCtrl;
		private AlbumImgControl albumImgCtrl;
		private SnsLoadingCtrl snsLoadingCtrl;
		private TextBlock descTxt;
		private SnsUserPageItem.AlbumItemStyle itemStyle;
		public static DependencyProperty ListItemProperty = DependencyProperty.Register("ItemObject", typeof(SnsUserPageItemData), typeof(SnsUserPageItem), new PropertyMetadata(null, new PropertyChangedCallback(SnsUserPageItem.OnItemPropertyChanged)));
		internal StackPanel LayoutRoot;
		private bool _contentLoaded;
		public event SnsUserPageItem.AlbumImageClick SnsImageClick;
		public SnsUserPageItemData ItemObject
		{
			get
			{
				return (SnsUserPageItemData)base.GetValue(SnsUserPageItem.ListItemProperty);
			}
			set
			{
				base.SetValue(SnsUserPageItem.ListItemProperty, value);
			}
		}
		public SnsUserPageItem()
		{
			base.add_Loaded(new RoutedEventHandler(this.SnsUserPageItem_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.SnsUserPageItem_Unloaded));
			this.itemStyle = SnsUserPageItem.AlbumItemStyle.unknown;
			this.InitializeComponent();
			this.InitBindResource();
		}
		private void SnsUserPageItem_Unloaded(object sender, RoutedEventArgs e)
		{
		}
		private void SnsUserPageItem_Loaded(object sender, RoutedEventArgs e)
		{
		}
		private void InitBindResource()
		{
		}
		private static void OnItemPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == SnsUserPageItem.ListItemProperty)
			{
				(dependencyObject_0 as SnsUserPageItem).OnListItemPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void OnListItemPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			try
			{
				this.RefreshItem(dependencyPropertyChangedEventArgs_0.get_NewValue() as SnsUserPageItemData);
			}
			catch (Exception ex)
			{
				Log.smethod_1(base.GetType().get_Name(), ex.get_StackTrace());
			}
		}
		private void RefreshDataTxt(SnsUserPageItemData item, Grid dataPanel)
		{
			dataPanel = (Grid)UIElementTraveler.FindElementRecursive(this, typeof(Grid));
			if (dataPanel == null)
			{
				dataPanel = new Grid();
				dataPanel.set_Width(168.0);
				this.LayoutRoot.get_Children().Add(dataPanel);
			}
			this.albumDataCtrl = (AlbumDataControl)UIElementTraveler.FindElementRecursive(dataPanel, typeof(AlbumDataControl));
			if (item.bIsNeedShowData)
			{
				if (this.albumDataCtrl == null)
				{
					this.albumDataCtrl = new AlbumDataControl();
					dataPanel.get_Children().Add(this.albumDataCtrl);
				}
				this.albumDataCtrl.SetContent(item);
				return;
			}
			if (this.albumDataCtrl != null)
			{
				dataPanel.get_Children().Clear();
				this.albumDataCtrl = null;
			}
		}
		private void RefreshNumTxt(SnsUserPageItemData item)
		{
			if (item.tloObj == null)
			{
				return;
			}
			this.descTxt = (TextBlock)UIElementTraveler.FindElementRecursive(this, typeof(TextBlock));
			if (item.tloObj.content.nStyle != 1)
			{
				return;
			}
			if (item.tloObj.content.mediaList.get_Count() != 1)
			{
				if (this.descTxt == null)
				{
					this.descTxt = new TextBlock();
					this.descTxt.set_FontSize(18.0);
					this.descTxt.set_Foreground(R.theme.SNS_USERPAGEITEM_PHOTONUM_BRUSH);
					this.descTxt.set_VerticalAlignment(2);
					this.descTxt.set_Margin(new Thickness(10.0, 0.0, 0.0, 0.0));
					this.LayoutRoot.get_Children().Add(this.descTxt);
				}
				this.descTxt.set_Text(string.Format(strings.Album_List_Total, item.tloObj.content.mediaList.get_Count().ToString()));
				return;
			}
			if (this.descTxt != null)
			{
				this.LayoutRoot.get_Children().Remove(this.descTxt);
			}
		}
		private void RefreshImgCtrl(SnsUserPageItemData item)
		{
			this.albumImgCtrl = (AlbumImgControl)UIElementTraveler.FindElementRecursive(this, typeof(AlbumImgControl));
			if (this.albumImgCtrl == null)
			{
				this.albumImgCtrl = new AlbumImgControl();
				this.albumImgCtrl.set_Height(200.0);
				this.albumImgCtrl.set_Width(200.0);
				this.albumImgCtrl.ImageClick += new AlbumImgControl.SnsImageClick(this.albumImgCtrl_ImageClick);
				this.LayoutRoot.get_Children().Add(this.albumImgCtrl);
			}
			if (item.strObjectId == "TakingPhotoIcon")
			{
				this.albumImgCtrl.LoadTakePhotoIcon();
			}
			else
			{
				this.albumImgCtrl.LoadSnsInfoImage(item.tloObj, item.mGroupList);
			}
			if (string.IsNullOrEmpty(item.strDescription))
			{
				this.albumImgCtrl.ClearDescContent();
			}
			else
			{
				this.albumImgCtrl.SetDescContent(item.strDescription);
			}
			if (item.nStatus == SnsInfoStatus.STATUS_ERROR)
			{
				this.albumImgCtrl.SetErrorIcon();
				return;
			}
			this.albumImgCtrl.ClearErrorIcon();
		}
		private void RefreshItem(SnsUserPageItemData item)
		{
			if (item == null)
			{
				return;
			}
			if (item.strObjectId == "Cover")
			{
				this.albumCoverCtrl = (AlbumCoverCtrl)UIElementTraveler.FindElementRecursive(this, typeof(AlbumCoverCtrl));
				if (this.albumCoverCtrl == null)
				{
					this.LayoutRoot.set_Margin(new Thickness(0.0, 0.0, 0.0, 36.0));
					this.LayoutRoot.get_Children().Clear();
					PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
					BasePage basePage = phoneApplicationFrame.get_Content() as BasePage;
					SnsUserMainPage snsUserMainPage = basePage as SnsUserMainPage;
					this.albumCoverCtrl = new AlbumCoverCtrl(snsUserMainPage.contact, false);
					this.LayoutRoot.get_Children().Add(this.albumCoverCtrl);
				}
				this.albumCoverCtrl.RefreshCoverImage();
				this.itemStyle = SnsUserPageItem.AlbumItemStyle.albumCoverItem;
				return;
			}
			if (!(item.strObjectId == "TakingPhotoIcon"))
			{
				if (item.tloObj == null || item.tloObj.content.nStyle != 1)
				{
					if (item.strObjectId == "Loading")
					{
						this.snsLoadingCtrl = (SnsLoadingCtrl)UIElementTraveler.FindElementRecursive(this, typeof(SnsLoadingCtrl));
						if (this.snsLoadingCtrl == null)
						{
							this.LayoutRoot.set_Margin(new Thickness(0.0, 0.0, 0.0, 16.0));
							this.LayoutRoot.get_Children().Clear();
							this.snsLoadingCtrl = new SnsLoadingCtrl();
							this.LayoutRoot.get_Children().Add(this.snsLoadingCtrl);
						}
						this.snsLoadingCtrl.modeType = LoadingState.LoadingMode;
						this.itemStyle = SnsUserPageItem.AlbumItemStyle.albumLoadingItem;
						return;
					}
					if (item.strObjectId == "ToLoad")
					{
						this.snsLoadingCtrl = (SnsLoadingCtrl)UIElementTraveler.FindElementRecursive(this, typeof(SnsLoadingCtrl));
						if (this.snsLoadingCtrl == null)
						{
							this.LayoutRoot.set_Margin(new Thickness(0.0, 0.0, 0.0, 16.0));
							this.LayoutRoot.get_Children().Clear();
							this.snsLoadingCtrl = new SnsLoadingCtrl();
							this.LayoutRoot.get_Children().Add(this.snsLoadingCtrl);
						}
						this.snsLoadingCtrl.modeType = LoadingState.PullToShowMoreMode;
						this.itemStyle = SnsUserPageItem.AlbumItemStyle.albumLoadingItem;
						return;
					}
					if (item.strObjectId == "NoMorePic")
					{
						this.snsLoadingCtrl = (SnsLoadingCtrl)UIElementTraveler.FindElementRecursive(this, typeof(SnsLoadingCtrl));
						if (this.snsLoadingCtrl == null)
						{
							this.LayoutRoot.set_Margin(new Thickness(0.0, 0.0, 0.0, 10.0));
							this.LayoutRoot.get_Children().Clear();
							this.snsLoadingCtrl = new SnsLoadingCtrl();
							this.LayoutRoot.get_Children().Add(this.snsLoadingCtrl);
						}
						this.snsLoadingCtrl.modeType = LoadingState.ContactEndMode;
						this.itemStyle = SnsUserPageItem.AlbumItemStyle.albumLoadingItem;
						return;
					}
					if (item.strObjectId == "StrangerNoMorePic")
					{
						this.snsLoadingCtrl = (SnsLoadingCtrl)UIElementTraveler.FindElementRecursive(this, typeof(SnsLoadingCtrl));
						if (this.snsLoadingCtrl == null)
						{
							this.LayoutRoot.set_Margin(new Thickness(0.0, 0.0, 0.0, 16.0));
							this.LayoutRoot.get_Children().Clear();
							this.snsLoadingCtrl = new SnsLoadingCtrl();
							this.LayoutRoot.get_Children().Add(this.snsLoadingCtrl);
						}
						this.snsLoadingCtrl.modeType = LoadingState.StrangerEndMode;
						this.itemStyle = SnsUserPageItem.AlbumItemStyle.albumLoadingItem;
						return;
					}
					if (item.strObjectId == "TakePicNow")
					{
						this.snsLoadingCtrl = (SnsLoadingCtrl)UIElementTraveler.FindElementRecursive(this, typeof(SnsLoadingCtrl));
						if (this.snsLoadingCtrl == null)
						{
							this.LayoutRoot.set_Margin(new Thickness(0.0, 0.0, 0.0, 16.0));
							this.LayoutRoot.get_Children().Clear();
							this.snsLoadingCtrl = new SnsLoadingCtrl();
							this.LayoutRoot.get_Children().Add(this.snsLoadingCtrl);
						}
						this.snsLoadingCtrl.modeType = LoadingState.ToTakePhotoTipMode;
						this.itemStyle = SnsUserPageItem.AlbumItemStyle.albumLoadingItem;
					}
					return;
				}
			}
			if (this.itemStyle != SnsUserPageItem.AlbumItemStyle.albumImgItem)
			{
				this.LayoutRoot.set_Margin(new Thickness(0.0, 0.0, 0.0, 36.0));
				this.LayoutRoot.get_Children().Clear();
			}
			this.RefreshDataTxt(item, this.dataPanel);
			this.RefreshImgCtrl(item);
			this.RefreshNumTxt(item);
			this.itemStyle = SnsUserPageItem.AlbumItemStyle.albumImgItem;
		}
		private void albumImgCtrl_ImageClick(object sender, object object_0)
		{
			if (this.SnsImageClick != null)
			{
				this.SnsImageClick(this, this.ItemObject);
			}
		}
		public void Refresh()
		{
			this.RefreshItem(this.ItemObject);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Sns/Album/UI/SnsUserPageItem.xaml", 2));
			this.LayoutRoot = (StackPanel)base.FindName("LayoutRoot");
		}
	}
}
